
# ==================================================================================================
# CMake
# ==================================================================================================
cmake_minimum_required(VERSION 3.10)

# ==================================================================================================
# Project declaration
# ==================================================================================================
project(Zoo VERSION 1.0.0)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
SET(CMAKE_CXX_FLAGS "-fmodules-ts")
# ==================================================================================================
# Options
# ==================================================================================================
option(option_test ": option_test................." OFF)
option(USE_BASE "Use tutorial provided base implementation" ON)
option(USE_CORE "Use tutorial provided base implementation" ON)

# ==================================================================================================
# configure_file
# ==================================================================================================
configure_file(TutorialConfig.h.in TutorialConfig.h)

# ==================================================================================================
# set
# set (normal_var a)
# message (">>> value = ${normal_var}")
# >>> value = a
# ==================================================================================================
set(set_test "set_test....................")


# ==================================================================================================
# CMake policies cmake 版本控制
# ==================================================================================================
#if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.12")
#    cmake_policy(SET CMP0074 NEW)
#endif()


# ==================================================================================================
# CMake policies cmake 添加库
# ==================================================================================================

if(USE_BASE)
  add_subdirectory(Base)
  list(APPEND EXTRA_LIBS Base)
endif()

if(USE_CORE)
  add_subdirectory(Core)
  list(APPEND EXTRA_LIBS Core)
endif()




# 添加一个库
#add_library(Base base.cpp)

# 添加 MathFunctions 库
#add_subdirectory(Base)
#target_link_libraries(Soar PUBLIC Base)

#set(ZOO_SRCS
#        ${PROJECT_BINARY_DIR}/Config.cxx
#        Zoo/Zoo.cxx
#)

#通配符方式
#file(GLOB ZOO_SRCS "src/*.cpp")

file(GLOB ZOO_SRCS 
      "${PROJECT_BINARY_DIR}/*.h"
      "Zoo/*.cc"
)

add_executable(${PROJECT_NAME} ${ZOO_SRCS})

# PRIVATE - 将目录添加到此目标的include目录中
# INTERFACE - 将该目录添加到任何链接到此库的目标的include目录中（不包括自己）
# PUBLIC - 它包含在此库中，也包含在链接此库的任何目标中
target_link_libraries(${PROJECT_NAME} PUBLIC ${EXTRA_LIBS})

# 将二进制目录添加到 include 文件的搜索路径
# 这样我们就可以找到 TutorialConfig.h 了
target_include_directories(Zoo PUBLIC
                          "${PROJECT_BINARY_DIR}"
                          "${PROJECT_BINARY_DIR}/Base/gcm.cache"
                          "${PROJECT_BINARY_DIR}/Core/gcm.cache"
                          )

# Set the directories that should be included in the build command for this target
# when running g++ these will be included as -I/directory/path/
SET_TARGET_PROPERTIES(Zoo PROPERTIES LINKER_LANGUAGE C
      RUNTIME_OUTPUT_DIRECTORY "Bin"
      OUTPUT_NAME "Zoo"
      PREFIX "")

set(publih_lib_include "${PROJECT_BINARY_DIR}/gcm.cache")

# 拷贝文件夹到指定的目录
add_custom_target(copy_files ALL  
VERBATIM 
# COMMAND_EXPAND_LISTS 
COMMAND ${CMAKE_COMMAND} -E make_directory "${publih_lib_include}" 
) 

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})

# CMAKE_SOURCE_DIR 根源目录
# CMAKE_CURRENT_SOURCE_DIR 如果使用子项目和目录，则为当前源目录
# PROJECT_SOURCE_DIR 当前 cmake 项目的源目录
# CMAKE_BINARY_DIR 根二进制文件生成目录。这是运行cmake命令的目录
# CMAKE_CURRENT_BINARY_DIR 你当前所处的生成目录
# PROJECT_BINARY_DIR 当前项目的生成目录

# https://www.cnblogs.com/juzaizai/p/15069300.html